package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.ReservationDto;
import com.zzyl.service.CustomerReservationService;
import com.zzyl.utils.UserThreadLocal;
import com.zzyl.vo.ReservationVo;
import com.zzyl.vo.TimeReservationCountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/customer/reservation")
@Api(tags = "客户预约管理")
public class CustomerReservationController extends BaseController {

    @Autowired
    CustomerReservationService customerReservationService;
    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public ResponseResult<Integer> getCancelledReservationCount() {
     Integer count=customerReservationService.getCancelledCount();
     return success(count);
    }

    @GetMapping("/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public ResponseResult<List<TimeReservationCountVo>> getReservationCount(Long time){
       List<TimeReservationCountVo> timeReservationCountVos= customerReservationService.getTimeReservationCount(time);
       return success(timeReservationCountVos);
    }


    @ApiOperation("新增预约")
    @PostMapping
    public ResponseResult addReservation(
            @RequestBody ReservationDto reservationDto
            ){
        customerReservationService.addReservation(reservationDto);
        return success();
    }
    @ApiOperation("分页查询预约")
    @GetMapping("/page")
    public ResponseResult<PageResponse<ReservationVo>> pageQuery(
          Integer pageNum,
          Integer pageSize,
          Integer status
    ){
       PageResponse<ReservationVo>responsePage= customerReservationService.pageQuery(pageNum,pageSize,status);
        return success(responsePage);
    }

    @ApiOperation("取消预约")
    @PutMapping("/{id}/cancel")
    public ResponseResult cancelRe(
            @PathVariable("id")Integer id
            ){
        customerReservationService.cancel(id);
        return success();
    }

}